<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<input type="hidden" name="keyId" id="keyId" value="">
<input type="hidden" name="keyIds"  id="keyIds">
<input type="hidden" name="keyNames"  id="keyNames">
<div class="row" style="padding:2px">
  <div class="col-sm-12 col-md-4 col-lg-4">
    <h5><label style="width:100%"> <span class="label  label-success"> 提示：请选择要导出的字段</span> </label>
    </h5><a id="ajax_permission_btn_add" class="btn btn-default " data-toggle="modal"><i class="fa fa-lg fa-flash"></i> 导出</a>
  </div>
</div>
<!-- rows -->
<!-- widget grid -->
<section id="widget-grid" class="">

  <!-- row -->
  <div class="row">

    <!-- NEW WIDGET START -->
    <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

      <!-- Widget ID (each widget will need unique ID)-->
      <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false"
           data-widget-colorbutton="false"
           data-widget-togglebutton="false"
           data-widget-deletebutton="false"
           data-widget-fullscreenbutton="true"
           data-widget-custombutton="false"
           data-widget-sortable="false">

        <header>
          <span class="widget-icon"> <i class="fa fa-table"></i> </span>
          <h2>导出字段</h2>
          <div class="widget-toolbar">
          </div>
        </header>

        <!-- widget div-->
        <div>
          <!-- widget edit box -->
          <div class="jarviswidget-editbox">
            <!-- This area used as dropdown edit box -->
          </div>
          <!-- end widget edit box -->

          <!-- widget content -->
          <div class="widget-body no-padding">
            <div id="ajax_permission_tree_div" class="col-xs-12 col-sm-4 col-md-4 col-lg-6" style="min-width:440px">
            </div>
            <div id="ajax_permission_grid_div" class="col-xs-12 col-sm-8 col-md-8 col-lg-6" style="min-width:440px">
            </div>
            <div class="row">
              <div class="col-sm-12 col-md-12 col-lg-5">
                <div class="well well-light well-sm no-margin no-padding">
                  <div class="row">
                    <div class="col-sm-12">
                      <ul id="tree" class="ztree" style="max-height:500px;min-width:340px; overflow:auto;"></ul>
                    </div>
                  </div>
                </div>
              </div>

            </div>
          </div>
          <!-- end widget content -->

        </div>
        <!-- end widget div -->

      </div>
      <!-- end widget -->

    </article>
    <!-- WIDGET END -->

  </div>

  <!-- end row -->

  <!-- end row -->

</section>
<!-- end widget grid -->
<script type="text/javascript">
  // DO NOT REMOVE : GLOBAL FUNCTIONS!
  pageSetUp();
  function reload(){
    loadURL("ajax!permission.action",$('#content'));
  }
</script>
<script type="text/javascript">
  function loadCategoryTree(){
    var setting = {
      check: {
        enable: true

      },
      view: {
        dblClickExpand: false,
        showLine: true,
        selectedMulti: false
      },
      data: {
        simpleData: {
          enable:true,
          idKey: "id",
          pIdKey: "pId",
          rootPId: ""
        }
      },
      callback: {
        onCheck : onNodeClick1
      }
    };
    $.ajax({
      type: "get",
      url: 'ajax-export!zTree.action',
      success: function(data){
        if(data.result.errorCode == "1"){
          var t = $("#tree");
          t = $.fn.zTree.init(t, setting, data.data.data);
        }
      }
    });
  }
  function onNodeClick1(event, treeId, treeNode){
    var treeObj=$.fn.zTree.getZTreeObj("tree"),
            nodes=treeObj.getCheckedNodes(true),
            key="";
    title="";
    for(var i=0;i<nodes.length;i++){
      key+=nodes[i].id + ",";
      if(nodes[i].intLevel==2){
        title+=nodes[i].name+",";
      }
    }
    $("#keyIds").val(key);
    $("#keyNames").val(title)
  }

  function iconFormat(cellvalue, options, cell){

    return "<i class='fa fa-lg fa-fw "+cellvalue+"'></i>";
  }

  $(function(){
    loadCategoryTree();
    //run_jqgrid_function();
  })
  $("a#ajax_permission_btn_add").unbind("click").bind("click",function(){
    window.location.href="ajax-export!export.action?keyIds="+$("#keyIds").val()+"&keyNames="+$("#keyNames").val();
  })
  $(window).on('resize.jqGrid', function() {
    jQuery("#ajax_permission_list_table").jqGrid('setGridWidth', $("#ajax_permission_list_row").width());
  });

  jQuery("#ajax_permission_list_table").jqGrid('navGrid', "#ajax_permission_list_page", {
    edit : false,
    add : false,
    del : false,
    search:false
  });


</script>
